import time

from selenium.webdriver.support.wait import WebDriverWait

from config import PATH


class AppBasePage(object):
    def __init__(self, driver):
        self.driver = driver

    def app_fd_element(self, loc):
        """
        :param loc: 元素定位
        :return: 元素
        """
        try:
            ele = WebDriverWait(self.driver, 10).until(lambda x: x.find_element(*loc))
            return ele
        except Exception as e:
            print("元素定位失败：{}".format(e))
            raise

    def app_base_click(self, loc):
        """
        :param loc: 元素定位
        :return: 无
        """
        self.app_fd_element(loc).click()

    def app_base_send_keys(self, loc, text):
        """
        :param loc: 元素定位
        :param text: 输入内容
        :return: 无
        """
        self.app_fd_element(loc).clear()
        self.app_fd_element(loc).send_keys(text)

    def app_shot(self, img_name):
        """
        :param img_name: 图片描述
        :return: 无
        """
        self.driver.get_screenshot_as_file(PATH+"/img/{}.png".format(img_name))
